<template>
  <div>
    <div id="editor"></div>

    
  </div>
</template>
<script>

import E from "wangeditor";
import axios from "axios";
export default {
 
  props: {},
  data() {
    return {
      editor: "",
      modulePictures: [],
    };
  },
  mounted() {
    this.seteditor();
  },
  methods: {
    seteditor() {
      var that = this;

      // http://192.168.2.125:8080/admin/storage/create
      this.editor = new E("#editor");
      console.log(this.editor);
      this.editor.config.zIndex = 500;
      this.editor.config.uploadImgShowBase64 = false; // base 64 存储图片
      this.editor.config.excludeMenus = ["emoticon", "video"];

      this.editor.config.customUploadImg = function (resultFiles, insertImgFn) {
        var forms = new FormData();
        var configs = {
          headers: { "Content-Type": "multipart/form-data" },
        };
        forms.append("multipartFile", resultFiles[0]);

        axios
          .post("http://150.158.157.233:8081/oss/addAvatar", forms, configs)
          .then((res) => {
            insertImgFn(res.data.data.url);

            var picture = {
              modelePicturename: res.data.data.fileName,
              modulePicturepath: res.data.data.url,
            };
            that._data.modulePictures.push(picture);
            console.log(that._data);
          });
      };
      this.editor.config.height = 500;
      this.editor.config.onchange =  (newHtml)=> {
        this.$emit("getContent", newHtml, this.modulePictures);
      };
      this.editor.create();
    },
    
  },
};
</script>
<style>
</style>